package com.ouken.com;

import com.gen.tool.SoundPlayer;
import com.ouken.asynTask.AsynCreateRoom;
//import com.ouken.tool.MplayerTool;
import com.ouken.tool.MyApp;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class CreateroomActivity extends Activity {
	private MyApp appState;
	private SharedPreferences userInfo;
	private	ImageButton ib_back;
	private ImageButton ib_createroom;
	//private MplayerTool mplayerTool ;
	private EditText roomname;
	private EditText passwd;
	private Context context;
	private	RelativeLayout RL_bg ;
	
	private void initView(){
		userInfo = getSharedPreferences("user_info", 0);
		appState = ((MyApp)getApplicationContext());
		//appState.setMusic(userInfo.getString("MUSIC", "ON").equals("ON"));
		appState.addActivity(CreateroomActivity.this);
		
		ib_back = (ImageButton)findViewById(R.id.createroomActivity_ib_back);
		
		ib_createroom = (ImageButton)findViewById(R.id.createroomActivity_ib_createroom);
		roomname = (EditText)findViewById(R.id.createroomActivity_et_roomname);
		passwd = (EditText)findViewById(R.id.createroomActivity_et_pwd);
		//mplayerTool = new MplayerTool(CreateroomActivity.this);
		RL_bg = (RelativeLayout)findViewById(R.id.relativeLayout_createroom_bg);
		   
		context = CreateroomActivity.this;
	}

	public void onCreate(Bundle savedInstanceState) {
		   
        super.onCreate(savedInstanceState);
        setContentView(R.layout.createroom);
        initView();
        
		
        
        RL_bg.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(CreateroomActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
			}
		});
		
		ib_back.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				SoundPlayer.playSound(R.raw.keypress_common);
				//mplayerTool.playButtonPressed(CreateroomActivity.this);
				CreateroomActivity.this.finish();
			}
		});
		ib_createroom.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				SoundPlayer.playSound(R.raw.keypress_common);
				//mplayerTool.playButtonPressed(CreateroomActivity.this);
				new AsynCreateRoom(context, appState, roomname.getText().toString(), passwd.getText().toString()).execute();
			}
		});
	}
}
